package cn.breeze.org.controller;

import cn.breeze.basic.annotation.PreAuthorize;
import cn.breeze.basic.exception.BusinessException;
import cn.breeze.basic.utils.ExcelUtil;
import cn.breeze.org.domain.Shop;
import cn.breeze.org.service.IShopAuditLogService;
import cn.breeze.org.domain.ShopAuditLog;
import cn.breeze.org.query.ShopAuditLogQuery;
import cn.breeze.basic.utils.AjaxResult;
import cn.breeze.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/shopAuditLog")
public class ShopAuditLogController {
    @Autowired
    private  IShopAuditLogService shopAuditLogService;


    /**
     * 保存和修改公用的
     * @param shopAuditLog  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    @PreAuthorize(name = "保存店铺审核日志", sn = "shopAuditLog:save")
    public AjaxResult addOrUpdate(@RequestBody ShopAuditLog shopAuditLog){
        try {
            if( shopAuditLog.getId()!=null)
                shopAuditLogService.update(shopAuditLog);
            else
                shopAuditLogService.save(shopAuditLog);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    @PreAuthorize(name = "删除店铺审核日志", sn = "shopAuditLog:delete")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            shopAuditLogService.remove(id);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试1");
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    @PreAuthorize(name = "获取店铺审核日志", sn = "shopAuditLog:get")
    public ShopAuditLog get(@PathVariable("id")Long id)
    {
        return shopAuditLogService.loadById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    @PreAuthorize(name = "获取所有店铺审核日志", sn = "shopAuditLog:getAll")
    public List<ShopAuditLog> list(){

        return shopAuditLogService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    @PreAuthorize(name = "列表店铺审核日志", sn = "shopAuditLog:list")
    public PageList<ShopAuditLog> queryData(@RequestBody ShopAuditLogQuery query)
    {
        return shopAuditLogService.queryData(query);
    }

    /**
    * @Title: loadByShopId
    * @Description: 根据shopId查询
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/3 20:12
    * @Parameters: []
    * @Return java.util.List<cn.breeze.org.domain.ShopAuditLog>
    */
    @GetMapping("/loadByShopId/{id}")
    @PreAuthorize(name = "根据店铺id获取店铺审核日志", sn = "shopAuditLog:loadByShopId")
    public List<ShopAuditLog> loadByShopId(@PathVariable("id")Long id){
        return shopAuditLogService.loadByShopId(id);
    }
}
